home *** CD-ROM | disk | FTP | other *** search
- /**
- * This is an example program which shows you how to write multithreaded
- * code safely with sub_arctic.
- */
- package sub_arctic.test;
-
- import sub_arctic.lib.label;
- import sub_arctic.lib.interactor_applet;
- import sub_arctic.lib.base_parent_interactor;
- import sub_arctic.lib.manager;
- import sub_arctic.lib.shadow_drag_container;
- import sub_arctic.lib.top_level;
- import sub_arctic.input.*;
-
- import java.util.Date;
-
- public class thread_test extends interactor_applet {
- label my_label;
- public void build_ui( base_parent_interactor top) {
- shadow_drag_container sdc;
- /* set it to say something when the clock is not yet ticking */
- my_label=new label("Starting out");
- /* set the position of the container, not the label */
- sdc=new shadow_drag_container(200,200);
- sdc.add_child(my_label);
- top.add_child(sdc);
- }
- /**
- * Now the interface is built, start your threads.
- */
- public void post_build_ui(base_parent_interactor top) {
- Thread t=new Thread(new time_display("Starting out",my_label));
- t.start();
- }
- }
- /**
- * This is a little parent class which can pop up a menu.
- */
- class time_display implements Runnable, work_proc {
- /* this is what the label is currently displaying */
- String _current_text;
- /* the label to manipulate ... but remember, only manipulate
- * it inside of run_safely().
- */
- label _the_label;
- /* make one of these by initializing the current text */
- public time_display(String t,label l) {
- _current_text=t;
- _the_label=l;
- }
- /**
- * Perform the main code of the thread.
- */
- public void run() {
- Date date;
- /* loop forever */
- while (true) {
- /* sleep for a quarter of a second */
- try {
- Thread.currentThread().sleep(250);
- } catch (InterruptedException e) {
- ; /* don't bother */
- }
- /* create a new date obj */
- date=new Date();
- /* has the time changed? */
- if (_current_text.equals(date.toString())) {
- continue;
- }
- /* set the current text to this date */
- _current_text=date.toString();
- /* it changed, fire off the change */
- manager.perform_work(this,_current_text);
-
- }
- }
- /**
- * This is the code that gets run on the "other side" of the
- * sub_arctic synchronization barrier. This code is allowed to
- * manipulate the interactors in any way it wants.
- */
- public void run_safely(Object o) {
- /* we know the object passed in is a string */
- String s=(String)o;
- /* update the text on the label to this string*/
- _the_label.set_text(s);
- /* note: you could have just accessed _current_text, but I wanted
- * to demonstrate the parameter passing */
- }
- }
- /*=========================== COPYRIGHT NOTICE ===========================
-
- This file is part of the subArctic user interface toolkit.
-
- Copyright (c) 1996 Scott Hudson and Ian Smith
- All rights reserved.
-
- The subArctic system is freely available for most uses under the terms
- and conditions described in
- http://www.cc.gatech.edu/gvu/ui/sub_arctic/sub_arctic/doc/usage.html
- and appearing in full in the lib/interactor.java source file.
-
- The current release and additional information about this software can be
- found starting at: http://www.cc.gatech.edu/gvu/ui/sub_arctic/
-
- ========================================================================*/
-